# messages.py
from pysage import Message
from util import vec2

# controller related messages
class InitializeAlbumsDataMessage(Message):
    '''this message is received by the albums viewer'''
    packet_type = 101

class InitializeAlbumsViewerMessage(Message):
    '''this message is received by the albums viewer'''
    packet_type = 102

class CloseApplicationMessage(Message):
    '''tell everything to close themselves'''
    packet_type = 103
    
# view related messages
# these messages are handled by the view
class AlbumSelectedMessage(Message):
    '''when a user selects an album to view, this message is received by the photo viewer'''
    properties = ['albumid']
    types = ('i',)
    packet_type = 104

class MoveThumbnailWindowMessage(Message):
    '''when a user translates the thumbnail window, this message sends the delta movement to the viewer'''
    properties = ['displacement']
    packet_type = 105
    def unpack_displacement(self, val):
        return vec2(*val)
    
class GrantFocusToViewerMessage(Message):
    '''when a user mouse enters the viewer window, we want to manually give it focus, so that mouse wheel events register'''
    packet_type = 106

class RevokeFocusFromViewerMessage(Message):
    '''similar, revoke upon mouse leaving window.  see grantfocusmessage'''
    packet_type = 107

class ZoomViewerMessage(Message):
    '''photoviewer zooms in and out according to user's scrollwheel'''
    properties = ['position', 'rotation']
    packet_type = 108
    def unpack_position(self, val):
        return vec2(*val)
    
class UserClickMessage(Message):
    '''message fired by a user clicking on the viewer'''
    properties = ['position']
    packet_type = 109
    
class AlbumPopUpMenuMessage(Message):
    '''message fired when a user right clicks on an album to edit the album's meta information, handled by the albumviewer'''
    properties = ['albumid']
    packet_type = 110
    
class ImageResourceUpdatedMessage(Message):
    '''when the resource worker thread updated an image resource to possibly give it better resolution
        sent by: resourcecontroller
        handled by : photoviewer
    '''
    properties = ['image', 'data']
    types = ['i', 'S']
    packet_type = 111

class ReloadImageResourceMessage(Message):
    '''request sent by the photoviewer to request more precise image data to be loaded by the resource controller'''
    properties = ['size', 'imageid', 'enforce_size']
    packet_type = 112
    types = (('i', 'i'), 'i', 'B')
    def pack_size(self, val):
        return (val.x, val.y)
    def unpack_size(self, val):
        return vec2(val[0], val[1])

class RemoveAlbumMessage(Message):
    properties = ['albumid']
    packet_type = 113
    types = ['i']
    
class FolderNotAdded(Message):
    properties = ['path']
    packet_type = 114
    types = ['p']





    
    
    
    

